#ifndef __FURNACE_RECIPES_MANAGER_H__
#define __FURNACE_RECIPES_MANAGER_H__

#include <cstdint>
#include <unordered_map>
#include <vector>
#include "nlohmann/json.hpp"

#include "GameSingleton.h"

namespace PocketSurvival
{

    struct FurnaceRecipe
    {
        // 合成出来的物品
        int32_t resultValue = 0;
        uint32_t resultCount = 0;
        // 副产物
        int32_t remainsValue = 0;
        uint32_t remainsCount = 0;
        // 需要的热量等级
        int32_t requiredHeatLevel = 0;
        // 配方
        int32_t ingredients[9];
        // 数据比特位，用于区分是否方块中的Data值等数据
        int32_t ingredientsDataBit[9];
        // 熔炼时间倍数
        float smeltingTimeMultiple;

        inline FurnaceRecipe();
    };

    inline FurnaceRecipe::FurnaceRecipe()
    {
        memset(ingredients, 0, sizeof(ingredients));
        memset(ingredientsDataBit, 0xFF, sizeof(ingredientsDataBit));
    }

    class FurnaceRecipesManager : public SimpleSingletonItem
    {
        friend class SimpleSingleton;
    private:
        std::unordered_map<uint8_t, std::vector<FurnaceRecipe*>> furnaceRecipesMap;

    private:
        FurnaceRecipesManager();
        ~FurnaceRecipesManager();
        FurnaceRecipesManager(const FurnaceRecipesManager &) = delete;
        FurnaceRecipesManager(FurnaceRecipesManager &&) = delete;
        FurnaceRecipesManager &operator=(const FurnaceRecipesManager &) = delete;
        FurnaceRecipesManager &operator=(FurnaceRecipesManager &&) = delete;

        static uint8_t ArrangeRecipe(int32_t *ingredients, int32_t *outIngredients);

    public:
        void addFurnaceRecipes(FurnaceRecipe *furnaceRecipe);
        void loadFurnaceRecipesSource(const nlohmann::json &jsonData);
        FurnaceRecipe *findFurnaceRecipes(int32_t *ingredients);

        void loadGame();
    };


} // namespace PocketSurvival


#endif
